//
//  UIColor+YKOCExectionCore.m
//  YKOCExection
//
//  Created by edward on 2020/6/13.
//  Copyright © 2020 edward. All rights reserved.
//

#import "UIColor+YKOCExectionCore.h"
#import "YKUIConst.h"

@implementation UIColor (YKOCExectionCore)

+ (UIColor *)yk_randomColor
{
    return [UIColor colorWithRed:(arc4random_uniform(255.0))/255.0 green:( arc4random_uniform(255.0))/255.0 blue:(arc4random_uniform(255.0))/255.0 alpha:1.0];
}

+ (UIColor *)yk_colorWithHexString:(NSString *)color alpha:(CGFloat)alpha
{
    //删除字符串中的空格
    return YKHEXCOLOR_(color, alpha);
}

+ (UIColor *)yk_tilingWithImageName:(NSString *)name
{
    UIImage *imgPattern = [UIImage imageNamed:name];
    UIColor *colorPattern = [[UIColor alloc] initWithPatternImage:imgPattern];
    return colorPattern;
}

+ (UIColor *)yk_colorWithHexString:(NSString *)color
{
    // 默认alpha值为1
    return [self yk_colorWithHexString:color alpha:1.0f];
}

/**
 *  @brief  根据颜色生成纯色图片
 *
 *  @return 纯色图片
 */
- (UIImage *)image {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, self.CGColor);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

+ (UIColor *)yk_normalLabelColor
{
    if (@available(iOS 13.0, *)) {
        return [UIColor labelColor];
    } else {
        return [UIColor blackColor];
    }
}

@end
